From 31974e02ca74a644e75059faed370b031f40f5c6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timm=20B=C3=A4der?= Date: Tue, 9 Jan 2018 06:12:46 +0100 Subject: [PATCH] renderbackground: Avoid excess css value lookups We iterate over all background layers twice, so only lookup blend mode vlaues once. --- gtk/gtkrenderbackground.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gtk/gtkrenderbackground.c b/gtk/gtkrenderbackground.c index 57a07413b8..7957f97b20 100644 --- a/gtk/gtkrenderbackground.c +++ b/gtk/gtkrenderbackground.c @@ -623,9 +623,9 @@ gtk_css_style_snapshot_background (GtkCssStyle *style, GtkCssValue *background_image; GtkCssValue *box_shadow; GtkCssValue *blend_modes; - GskBlendMode blend_mode; const GdkRGBA *bg_color; gint number_of_layers; + GskBlendMode *blend_mode_values; background_image = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BACKGROUND_IMAGE); bg_color = _gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BACKGROUND_COLOR)); @@ -646,13 +646,15 @@ gtk_css_style_snapshot_background (GtkCssStyle *style, blend_modes = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BACKGROUND_BLEND_MODE); number_of_layers = _gtk_css_array_value_get_n_values (background_image); + blend_mode_values = g_alloca (sizeof (GskBlendMode) * number_of_layers); for (idx = number_of_layers - 1; idx >= 0; idx--) { - blend_mode = _gtk_css_blend_mode_value_get (_gtk_css_array_value_get_nth (blend_modes, idx)); + blend_mode_values[idx] = _gtk_css_blend_mode_value_get (_gtk_css_array_value_get_nth (blend_modes, idx)); - if (blend_mode != GSK_BLEND_MODE_DEFAULT) - gtk_snapshot_push_blend (snapshot, blend_mode, "Background<%u>Blend<%u>", idx, blend_mode); + if (blend_mode_values[idx] != GSK_BLEND_MODE_DEFAULT) + gtk_snapshot_push_blend (snapshot, blend_mode_values[idx], "Background<%u>Blend<%u>", + idx, blend_mode_values[idx]); } if (!gdk_rgba_is_clear (bg_color)) @@ -660,9 +662,7 @@ gtk_css_style_snapshot_background (GtkCssStyle *style, for (idx = number_of_layers - 1; idx >= 0; idx--) { - blend_mode = _gtk_css_blend_mode_value_get (_gtk_css_array_value_get_nth (blend_modes, idx)); - - if (blend_mode == GSK_BLEND_MODE_DEFAULT) + if (blend_mode_values[idx] == GSK_BLEND_MODE_DEFAULT) { gtk_theming_background_snapshot_layer (&bg, idx, snapshot); } -- 2.30.2